/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Jayson Kiong
 */
public class UpdateAgentServlet extends HttpServlet {
    /**
     * edits the agent details
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        Connection con = DBConnector.connect();
       
        
        try{
        String agentcode = request.getParameter("agentcode");
        String name = request.getParameter("name");
        String street = request.getParameter("street");
        String city = request.getParameter("city");
        String zip = request.getParameter("zip");
        String email = request.getParameter("email");
        String contact = request.getParameter("contact");
        String remarks = request.getParameter("remarks");
        String commission = request.getParameter("commission");
        String id = request.getParameter("id");

            
        PreparedStatement ps = con.prepareStatement
            ("UPDATE quicklenddb.agent SET agentcode = ?, a_name=?, a_contact=?, a_email=?,a_street=?,a_city=?,a_zip=?,a_remarks=?,commission=? where AgentID=?");
                
                
                ps.setString(1, agentcode);
                ps.setString(2, name);
                ps.setString(3, contact);
                ps.setString(4, email);
                ps.setString(5, street);
                ps.setString(6, city);
                ps.setInt(7, Integer.valueOf(zip));
                ps.setString(8, remarks);
                ps.setFloat(9, Float.valueOf(commission));
                ps.setInt(10, Integer.valueOf(id));
             
                
                ps.executeUpdate();
                
               
                response.sendRedirect("AgentServlet");
            
            
        }catch(SQLException e)
        {
            System.out.println(e); 
            //Logger.getLogger(RegisterServlet.class.getName()).log(Level.SEVERE, null, e);
        }
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
